package com.atfcm.stack;

import java.util.function.BinaryOperator;

/**
 * @Author 96534
 * @create 2025/3/11 10:04
 */
public class MyArrayStack<T> {
    private int size;
    private T[] stack;
    private int top = -1;

    public MyArrayStack(int size) {
        this.size = size;
        stack = (T[]) new Object[size];
    }

    public boolean isEmpty(){
        return top == -1;
    }

    public boolean isFull(){
        return top == size - 1;
    }

    public void push(T value) {
        if(isFull()){
            throw new RuntimeException("Stack is full");
        }
        top++;
        stack[top] = value;
    }

    public T pop() {
        if(isEmpty()){
            throw new RuntimeException("Stack is empty");
        }
        return stack[top--];
    }
    public T peek() {
        if (top == -1) {
            return null;
        }
        return stack[top];
    }
    


}
